import javax.swing.*;

public class Menu extends JMenuBar{
    public static final int FONT = 5;

    public Menu() {
        /*
         * 创建一级菜单
         */
        JMenu optionMenu = new JMenu("<html><font size=" + FONT + ">选项</font></html>");
        JMenu settingMenu = new JMenu("<html><font size=" + FONT + ">设置</font></html>");
        JMenu aboutMenu = new JMenu("<html><font size=" + FONT + ">关于</font></html>");
        // 一级菜单添加到菜单栏
        this.add(optionMenu);
        this.add(settingMenu);
        this.add(aboutMenu);

        /*
         * 创建 "选项" 一级菜单的子菜单
         */
        JMenuItem standardItem = new JMenuItem("标准");
        JMenuItem hardItem = new JMenuItem("地狱");
        JMenuItem customItem = new JMenuItem("自定义");
        JMenuItem rankMenuItem = new JMenuItem("排名");
        JMenuItem recordMenuItem = new JMenuItem("本地记录");
        // 子菜单添加到一级菜单
        optionMenu.add(standardItem);
        optionMenu.add(hardItem);
        optionMenu.add(customItem);
        optionMenu.addSeparator();       // 添加一条分割线
        optionMenu.add(rankMenuItem);
        optionMenu.add(recordMenuItem);

        /*
        “设置”菜单子菜单
         */
        JCheckBoxMenuItem insRebornItem = new JCheckBoxMenuItem("立即重生");

        settingMenu.add(insRebornItem);

        standardItem.addActionListener(e -> {
            System.out.println("标准模式");
        });

        hardItem.addActionListener(e -> {
            System.out.println("地狱模式");
        });

        customItem.addActionListener(e -> {
            System.out.println("自定义模式");
        });

        rankMenuItem.addActionListener(e -> {
            System.out.println("排名");
        });

        recordMenuItem.addActionListener(e -> {
            System.out.println("本地记录");
        });

        insRebornItem.addChangeListener(e -> System.out.println("立即重生是否被选中: " + insRebornItem.isSelected()));

        aboutMenu.addActionListener(e -> {
            System.out.println("关于");
        });
    }
}
